import threading
import time
from BuyTicketUtil import BuyTicket

class TicketThread (threading.Thread):
    def __init__(self,session,flag,stationDict,passenger,threadID, name,smtpEmail):
        threading.Thread.__init__(self)
        self.session=session
        self.flag=flag
        self.stationDict=stationDict
        self.passenger=passenger
        self.threadID = threadID
        self.name = name
        self.stationTrainCodes=passenger['stationTrainCodes'].split(",")
        # 邮件
        self.smtpEmail=smtpEmail
        # 席别索引
        seatsList=['O','M','S']
        self.seatsIndex=seatsList.index(passenger['seats'])
    def run(self):
        print ("开启线程： " + self.name)
        buy(self.session,self.flag,self.stationDict,self.passenger,self.stationTrainCodes,self.seatsIndex,self.smtpEmail)

# 抢票逻辑
def buy(session,flag,stationDict,passenger,stationTrainCodes,seatsIndex,smtpEmail):
	task=BuyTicket(stationDict,passenger,stationTrainCodes,seatsIndex,smtpEmail)
	while task.successFlag != True:
		task.buyTicket(flag,session)